﻿using Core.Librarys;
using Core.Librarys.Image;
using Core.Models;
using Core.Servicers.Interfaces;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Imaging;
using UI.Controls;
using UI.Controls.Charts.Model;
using UI.Controls.Select;
using UI.Models;
using UI.Servicers;
using UI.Views;

namespace UI.ViewModels
{
    public class IndexPageVM : IndexPageModel
    {
        public Command ToDetailCommand { get; set; }
        public Command RefreshCommand { get; set; }
        private readonly MainViewModel main;
        private readonly IMain mainServicer;
        private readonly IInputServicer inputServicer;
        public List<SelectItemModel> MoreTypeOptions { get; set; }
        public IndexPageVM(
            MainViewModel main,
            IMain mainServicer,
            IInputServicer inputServicer)
        {
            this.main = main;
            this.mainServicer = mainServicer;
            this.inputServicer = inputServicer;

            RefreshCommand = new Command(new Action<object>(OnRefreshCommand));

            Init();
        }

        private void OnRefreshCommand(object obj)
        {
        }

        public override void Dispose()
        {
            PropertyChanged -= IndexPageVM_PropertyChanged;
            base.Dispose();
        }

        private void Init()
        {
            PropertyChanged += IndexPageVM_PropertyChanged;
            inputServicer.OnKeyUpInput += InputServicer_OnKeyUpInput;
        }

        private void InputServicer_OnKeyUpInput(object sender, System.Windows.Forms.Keys key)
        {
            if (key == System.Windows.Forms.Keys.F5)
            {
            }
        }

        private void OnTodetailCommand(object obj)
        {
            var data = obj as ChartsDataModel;

            if (data != null)
            {
                if (data.Data is DailyLogModel)
                {
                    var model = data.Data as DailyLogModel;
                    if (model != null && model.AppModel != null)
                    {
                        main.Data = model.AppModel;
                    }
                }

            }
        }

        private void IndexPageVM_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName == nameof(TabbarSelectedIndex))
            {
            }
        }
    }
}
